const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  entry: ['babel-polyfill', './src/main.js'],
  output: {
    filename: '[name].[hash:8].js'
  },
  mode: process.env.NODE_ENV,
  module: {
    rules: [
      {
        test: /\.(png|jpg|jpeg|gif)$/i,
        use: 'file-loader'
      },
      {
        test: /\.less$/i,
        use: [MiniCssExtractPlugin.loader, { loader: 'css-loader' }, { loader: 'less-loader' }]
      },
      {
        test: /\.css$/i,
        use: [MiniCssExtractPlugin.loader, { loader: 'css-loader' }]
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: [{ loader: 'babel-loader' }, { loader: 'eslint-loader' }]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html'
    }),
    new MiniCssExtractPlugin({
      filename: '[name].[hash:8].css'
    }),
    new CleanWebpackPlugin(),
  ],
  devServer: {
    contentBase: './dist/',
    host: '0.0.0.0',
    proxy: {
      '/search': {
        target: 'https://gitee.com',
        changeOrigin: true
      }
    }
  }
}
